package com.kaishengit.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import com.kaishengit.pojo.User;
import com.kaishengit.util.HibernateUtil;

public class UserDao {

	public User findUserNameAndPassWord(User user) {
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		Query query = session
				.createQuery("from User where username=:name and password=:pwd");
		query.setParameter("name", user.getUsername());
		query.setParameter("pwd", user.getPassword());
		User u = (User) query.uniqueResult();
		session.beginTransaction().commit();
		return u;
	}

	public void saveUser(User user) {
		Session session = HibernateUtil.getSession();
		session.beginTransaction();
		session.persist(user);
		session.beginTransaction().commit();
	}
}
